<template>
  <div>
      <h1>登录页面</h1>
      <p>用户名：<input type="text" name="" id="" v-model="username"></p>
      <p>密码：<input type="password" name="" id="" v-model="password"></p>
      <p><button @click="login" >登录</button></p>
  </div>
</template>


<script>
export default {
    data() {
        return {
            username:'zhangsan',
            password:'123'
        }
    },
    methods: {
        login(){
            let data = {
                username:this.username,
                password:this.password,
            }
            this.axios.post('/login/',data).then(resp=>{
                console.log(resp)
                if(resp.data.code==0){
                    alert("登录成功")
                    localStorage.token = resp.data.token
                    localStorage.uid = resp.data.uid
                    localStorage.username = resp.data.username
                    localStorage.role = resp.data.role
                    localStorage.email = resp.data.email
                    location.href = '/'
                }else{
                    alert('登录失败')
                }                
            })
        }
    },
}
</script>


<style>


</style>